My First Flipbook

With flipbookr and xaringan

Thomas Gorman

2023-08-11

Book 1

### First flipbook!

cars
   speed dist
1      4    2
2      4   10
3      7    4
4      7   22
5      8   16
6      9   10
7     10   18
8     10   26
9     10   34
10    11   17
11    11   28
12    12   14
13    12   20
14    12   24
15    12   28
16    13   26
17    13   34
18    13   34
19    13   46
20    14   26
21    14   36
22    14   60
23    14   80
24    15   20
25    15   26
26    15   54
27    16   32
28    16   40
29    17   32
30    17   40
31    17   50
32    18   42
33    18   56
34    18   76
35    18   84
36    19   36
37    19   46
38    19   68
39    20   32
40    20   48
41    20   52
42    20   56
43    20   64
44    22   66
45    23   54
46    24   70
47    24   92
48    24   93
49    24  120
50    25   85

### First flipbook!

cars %>%
  ggplot()

### First flipbook!

cars %>%
  ggplot() +
  aes(x = speed)

### First flipbook!

cars %>%
  ggplot() +
  aes(x = speed) +
  aes(y = dist)

### First flipbook!

cars %>%
  ggplot() +
  aes(x = speed) +
  aes(y = dist) +
  geom_point(
             shape = 21,
             size = 7,
             color = "magenta",
             alpha = .8
             )

### First flipbook!

cars %>%
  ggplot() +
  aes(x = speed) +
  aes(y = dist) +
  geom_point(
             shape = 21,
             size = 7,
             color = "magenta",
             alpha = .8
             ) +
  aes(fill = speed)

### First flipbook!

cars %>%
  ggplot() +
  aes(x = speed) +
  aes(y = dist) +
  geom_point(
             shape = 21,
             size = 7,
             color = "magenta",
             alpha = .8
             ) +
  aes(fill = speed) +
  scale_fill_viridis_c()

### First flipbook!

cars %>%
  ggplot() +
  aes(x = speed) +
  aes(y = dist) +
  geom_point(
             shape = 21,
             size = 7,
             color = "magenta",
             alpha = .8
             ) +
  aes(fill = speed) +
  scale_fill_viridis_c() +
  theme_minimal()

Book 2

Flipbookr Runthrough

gss_sm
# A tibble: 2,867 × 32
    year    id ballot       age childs sibs   degree race  sex   region income16
   <dbl> <dbl> <labelled> <dbl>  <dbl> <labe> <fct>  <fct> <fct> <fct>  <fct>   
 1  2016     1 1             47      3 2      Bache… White Male  New E… $170000…
 2  2016     2 2             61      0 3      High … White Male  New E… $50000 …
 3  2016     3 3             72      2 3      Bache… White Male  New E… $75000 …
 4  2016     4 1             43      4 3      High … White Fema… New E… $170000…
 5  2016     5 3             55      2 2      Gradu… White Fema… New E… $170000…
 6  2016     6 2             53      2 2      Junio… White Fema… New E… $60000 …
 7  2016     7 1             50      2 2      High … White Male  New E… $170000…
 8  2016     8 3             23      3 6      High … Other Fema… Middl… $30000 …
 9  2016     9 1             45      3 5      High … Black Male  Middl… $60000 …
10  2016    10 3             71      4 1      Junio… White Male  Middl… $60000 …
# ℹ 2,857 more rows
# ℹ 21 more variables: relig <fct>, marital <fct>, padeg <fct>, madeg <fct>,
#   partyid <fct>, polviews <fct>, happy <fct>, partners <fct>, grass <fct>,
#   zodiac <fct>, pres12 <labelled>, wtssall <dbl>, income_rc <fct>,
#   agegrp <fct>, ageq <fct>, siblings <fct>, kids <fct>, religion <fct>,
#   bigregion <fct>, partners_rc <fct>, obama <dbl>

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion)
# A tibble: 2,867 × 32
# Groups:   bigregion, religion [24]
    year    id ballot       age childs sibs   degree race  sex   region income16
   <dbl> <dbl> <labelled> <dbl>  <dbl> <labe> <fct>  <fct> <fct> <fct>  <fct>   
 1  2016     1 1             47      3 2      Bache… White Male  New E… $170000…
 2  2016     2 2             61      0 3      High … White Male  New E… $50000 …
 3  2016     3 3             72      2 3      Bache… White Male  New E… $75000 …
 4  2016     4 1             43      4 3      High … White Fema… New E… $170000…
 5  2016     5 3             55      2 2      Gradu… White Fema… New E… $170000…
 6  2016     6 2             53      2 2      Junio… White Fema… New E… $60000 …
 7  2016     7 1             50      2 2      High … White Male  New E… $170000…
 8  2016     8 3             23      3 6      High … Other Fema… Middl… $30000 …
 9  2016     9 1             45      3 5      High … Black Male  Middl… $60000 …
10  2016    10 3             71      4 1      Junio… White Male  Middl… $60000 …
# ℹ 2,857 more rows
# ℹ 21 more variables: relig <fct>, marital <fct>, padeg <fct>, madeg <fct>,
#   partyid <fct>, polviews <fct>, happy <fct>, partners <fct>, grass <fct>,
#   zodiac <fct>, pres12 <labelled>, wtssall <dbl>, income_rc <fct>,
#   agegrp <fct>, ageq <fct>, siblings <fct>, kids <fct>, religion <fct>,
#   bigregion <fct>, partners_rc <fct>, obama <dbl>

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally()
# A tibble: 24 × 3
# Groups:   bigregion [4]
   bigregion religion       n
   <fct>     <fct>      <int>
 1 Northeast Protestant   158
 2 Northeast Catholic     162
 3 Northeast Jewish        27
 4 Northeast None         112
 5 Northeast Other         28
 6 Northeast <NA>           1
 7 Midwest   Protestant   325
 8 Midwest   Catholic     172
 9 Midwest   Jewish         3
10 Midwest   None         157
# ℹ 14 more rows

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1))
# A tibble: 24 × 4
# Groups:   bigregion [4]
   bigregion religion       n   pct
   <fct>     <fct>      <int> <dbl>
 1 Northeast Protestant   158  32.4
 2 Northeast Catholic     162  33.2
 3 Northeast Jewish        27   5.5
 4 Northeast None         112  23  
 5 Northeast Other         28   5.7
 6 Northeast <NA>           1   0.2
 7 Midwest   Protestant   325  46.8
 8 Midwest   Catholic     172  24.7
 9 Midwest   Jewish         3   0.4
10 Midwest   None         157  22.6
# ℹ 14 more rows

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na()
# A tibble: 20 × 4
# Groups:   bigregion [4]
   bigregion religion       n   pct
   <fct>     <fct>      <int> <dbl>
 1 Northeast Protestant   158  32.4
 2 Northeast Catholic     162  33.2
 3 Northeast Jewish        27   5.5
 4 Northeast None         112  23  
 5 Northeast Other         28   5.7
 6 Midwest   Protestant   325  46.8
 7 Midwest   Catholic     172  24.7
 8 Midwest   Jewish         3   0.4
 9 Midwest   None         157  22.6
10 Midwest   Other         33   4.7
11 South     Protestant   650  61.8
12 South     Catholic     160  15.2
13 South     Jewish        11   1  
14 South     None         170  16.2
15 South     Other         50   4.8
16 West      Protestant   238  37.7
17 West      Catholic     155  24.5
18 West      Jewish        10   1.6
19 West      None         180  28.5
20 West      Other         48   7.6

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na() |>
  ggplot(mapping =
           aes(x = pct,
               y = reorder(religion, -pct),
               fill = religion))

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na() |>
  ggplot(mapping =
           aes(x = pct,
               y = reorder(religion, -pct),
               fill = religion)) +
  geom_col()

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na() |>
  ggplot(mapping =
           aes(x = pct,
               y = reorder(religion, -pct),
               fill = religion)) +
  geom_col() +
    labs(x = "Percent", y = NULL)

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na() |>
  ggplot(mapping =
           aes(x = pct,
               y = reorder(religion, -pct),
               fill = religion)) +
  geom_col() +
    labs(x = "Percent", y = NULL) +
    guides(fill = "none")

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na() |>
  ggplot(mapping =
           aes(x = pct,
               y = reorder(religion, -pct),
               fill = religion)) +
  geom_col() +
    labs(x = "Percent", y = NULL) +
    guides(fill = "none") +
    facet_wrap(~ bigregion, ncol = 2)

Flipbookr Runthrough

gss_sm |>
  group_by(bigregion, religion) |>
  tally() |>
  mutate(pct = round((n/sum(n))*100, 1)) |>
  drop_na() |>
  ggplot(mapping =
           aes(x = pct,
               y = reorder(religion, -pct),
               fill = religion)) +
  geom_col() +
    labs(x = "Percent", y = NULL) +
    guides(fill = "none") +
    facet_wrap(~ bigregion, ncol = 2)